<?php
require_once ('Logger/Appender/File.php');
class Logger_Appender_SmsLog  extends Logger_Appender_File{

    protected $_options    =   array(
	'path'=>'',
	'buffer'=>0,
	);
	protected function _append(Logger_Event $event) {
		$msg    =   $event->getMessage();
		$this->_bufferSize += strlen ( $msg );
                $param  =   $event->getParam();
                $phone  =   isset($param['phone']) && !empty($param['phone'])?$param['phone']:'0';
                
                $file   =   date("Y-m-d",$event->getTimestamp())."/".substr($phone,-1,1).".log";
               // $fp =   $event->
		$this->_logBuffer [] = $file."|".$msg;

		if ($this->_bufferSize >= $this->_options['buffer'])
			$this->_flush ();
	}
	protected function _flush() {

              
               
                $fpBuffer = array();
                foreach($this->_logBuffer as $logStr)
                {
                    $tmp    =   explode("|",$logStr);
                    $file   =   $this->_options ['path']."/".$tmp[0];
                  
                    $dir = dirname ( $file );
                     
                    if (! is_dir ( $dir )) {
                        
			if ( !mkdir ($dir,0755,true ) )
				continue;

                    }
                   
                    $fp = fopen ( $file, 'a' );
                    $ret = fwrite ( $fp, $tmp[1]."\n" );
                    fclose ( $fp );

                }


                //$dir = $this->_options ['path']."/".date("Y-m-d");
		

		
		
		if ($ret)
		{
		    $this->_logBuffer     =   array ();
		    $this->_bufferSize    =   0;
		}


	}

	protected function _close()
	{

	}
    //put your code here
}
?>
